<%@ page language="java" contentType="text/html; charset=UTF-8"	 pageEncoding="UTF-8"%>
<%@ include file="../include/laypublic.jsp"%>
<!DOCTYPE html>
<html>
<head>
  <title>创效确认复制</title>
</head>
<style>
	.fieldset{
		margin-top: 5px;
		margin-bottom: 0px
	}
	.layui-legend{
		background-color:#5fb878;
		font-size:15px !important;
		width:140px;
	}
	.layui-form-item {
	    margin-bottom: 5px;
	    clear: both;
	    *zoom: 1;
	}
	.layui-form-label{width: 160px;}
	.right{
		float:right;
	}
	.width106{
		width:106px;
	}
	.width98{
		width:98px;
	}
	.width60{
		width:60px;
	}
</style>
<body>
<div class="layui-fluid">
    <div class="layui-card">
	    <div class="layui-tab-item layui-show">
	    	<div style="padding-top:15px;">&nbsp;</div>
			<form class="layui-form" id="addInfo_form" lay-filter="add_info_from">
				<fieldset class="layui-elem-field layui-field-title fieldset"  id="baseInfo">
				  <legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">项目基础信息  ></legend>
				  <div style="margin-top:20px">
				  	<div class="layui-form-item">
				  		<div class="layui-inline">
					      	<label class="layui-form-label">申请公司</label>
					      	<div class="layui-input-inline">
					      		<input type="hidden" name="effectOrgid" value="${bindOrgId}">
								<input type="text" value="${bindOrgName}" style="border:0px;" readonly="readonly" class="layui-input">
					      	</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">申请部门</label>
				      		<div class="layui-input-inline">
				      			<input type="hidden" name="effectDeptid" value="${bindDeptId}">
								<input type="text" value="${bindDeptName}" style="border:0px;" readonly="readonly" class="layui-input">
				      		</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">申请人</label>
				      		<div class="layui-input-inline">
				        		<input type="hidden" name="effectStaffApplyid" readonly="readonly" value="${SESSION_KEY_USER_DETAIL.hrStaffId }">
				        		<input type="text" name="staffname" value="${SESSION_KEY_USER_DETAIL.realName }" readonly="readonly" style="border:0px" class="layui-input">
				      		</div>
					    </div>
				    </div>
				    <div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">项目名称</label>
							<div class="layui-input-inline">
								<input type="text" name="proName" value="${effectSure.proName}" 
									style="border:0px;width:220px" readonly="readonly" class="layui-input">
								<input type="hidden" name="proCode" value="${effectSure.proCode}">
						        <input type="hidden" name="types" value="1">
						        <input type="hidden" name="sgCityId" value="${effectSure.sgCityId}">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">区域公司</label>
							<div class="layui-input-inline">
								<input type="text" value="${effectSure.orgAreName}" id ="query-input-hrOrgAreName" style="border: 0px;width:220px" 
							 		 readonly="readonly" class="layui-input">
								<input type="hidden" name="hrOrgAreaId" value="${effectSure.hrOrgAreaId}" id ="query-input-hrOrgAreName" style="border: 0px;width:220px" 
							 		 readonly="readonly" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">项目公司</label>
							<div class="layui-input-inline">
								<input type="text" name="hrOrgProName" value="${effectSure.orgProName}" id ="query-input-hrOrgAreName" style="border: 0px;width:220px" 
							 		 readonly="readonly" class="layui-input">
								<input type="hidden" name="hrOrgProId" value="${effectSure.hrOrgProId}" id ="query-input-hrOrgAreName" style="border: 0px;width:220px" 
							 		 readonly="readonly" class="layui-input">
							</div>
						</div>
					</div>
				    <div class="layui-form-item">
			  			<div class="layui-inline">
							<label class="layui-form-label">实施机构</label>
							<div class="layui-input-inline">
								<input type="text" value="${effectSure.carryOrg}" id ="query-input-carryOrg" style="border: 0px;width:220px" 
									lay-filter="query-input-carryOrg"
									name="carryOrg" readonly="readonly" class="layui-input">
							</div>
						</div>
				   		<div class="layui-inline">
							<label class="layui-form-label">项目负责人</label>
							<div class="layui-input-inline">
								<input type="text" value="${effectSure.proLeader}" id ="query-input-proLeader" style="border: 0px;" 
									lay-filter="query-input-proLeader"
									name="proLeader" readonly="readonly" class="layui-input">
							</div>
						</div>
				    	<div class="layui-inline">
							<label class="layui-form-label">创效月份</label>
							<div class="layui-input-inline">
								<input type="text" class="layui-input" 
								id="sent-laydate-year" value="<fmt:formatDate value="${effectSure.belongsMonth }" pattern="yyyy-MM"/>" name="effectMonth" 
								lay-verify="required" readonly>
							</div>
						</div>
				    </div>
				    <div class="layui-form-item">
					    <div class="layui-inline">
							<label class="layui-form-label">本月创效金额（元）</label>
							<div class="layui-input-inline">
								<input type="text" value="${effectSure.monthActAmount }" id="monthActAmount" style="border: 0px;" name="monthActAmount" readonly="readonly" class="layui-input">
							</div>
						</div>
					    <div class="layui-inline">
							<label class="layui-form-label">其中：建设期二三次经营利润 （元）</label>
							<div class="layui-input-inline">
								<input type="text" name="twoThreeProfit" value="${effectSure.twoThreeProfit }" maxlength="13" lay-verify="required|floatAmount" autocomplete="off" onblur="checkValueNumber(this);arabiaToCN(this,1);" class="layui-input">
							</div>
						</div>
					    <div class="layui-inline">
							<label class="layui-form-label">其中：针对运维期银行利率倒挂及自有资金利息亏损的经营利润 （元）</label>
							<div class="layui-input-inline">
								<input type="text" name="manageProfit" value="${effectSure.manageProfit }" maxlength="13" lay-verify="required|floatAmount" autocomplete="off" onblur="checkValueNumber(this);arabiaToCN(this,1);" class="layui-input">
							</div>
						</div>
					</div>
				    <div class="layui-form-item">
					    <div class="layui-inline">
							<label class="layui-form-label">月度计划创效金额（元）</label>
							<div class="layui-input-inline">
								<input type="text" value="${effectSure.monthPlanAmount }" id="query-input-monthPlanAmount" style="border: 0px;" name="monthPlanAmount" readonly="readonly" class="layui-input">
							</div>
						</div>
					    <div class="layui-inline">
							<label class="layui-form-label">月度计划完成比例（%）</label>
							<div class="layui-input-inline">
								<input type="text" value="${effectSure.monthDoneRate }" id="query-input-monthDoneRate" style="border: 0px;" name="monthDoneRate" readonly="readonly" class="layui-input">
							</div>
						</div>
					    <div class="layui-inline">
							<label class="layui-form-label">年度计划创效金额（元）</label>
							<div class="layui-input-inline">
								<input type="text" value="${effectSure.yearPlanAmount }" id="query-input-yearPlanAmount" style="border: 0px;" name="yearPlanAmount" readonly="readonly" class="layui-input">
							</div>
						</div>
					</div>
				    <div class="layui-form-item">
					    <div class="layui-inline">
							<label class="layui-form-label">年度计划完成比例（%）</label>
							<div class="layui-input-inline">
								<input type="hidden" value="" id="query-input-yearDoneAmount" style="border: 0px;" readonly="readonly" class="layui-input">
								<input type="text" value="${effectSure.yearDoneRate }" id="query-input-yearDoneRate" style="border: 0px;" name="yearDoneRate" readonly="readonly" class="layui-input">
							</div>
						</div>
					    <div class="layui-inline">
							<label class="layui-form-label">小微是否签订</label>
							<div class="layui-input-inline">
								<select name="signFlag" lay-verify="required">
					      			<option value="">请选择</option>
					      			<option value="0" <c:if test="${effectSure.signFlag == '0'}">selected</c:if>>否</option>
					      			<option value="1" <c:if test="${effectSure.signFlag == '1'}">selected</c:if>>是</option>
								</select>
							</div>
						</div>
					    <div class="layui-inline">
							<label class="layui-form-label">应缴风险抵押金金额（元）</label>
							<div class="layui-input-inline">
								<input type="text" value="${effectSure.shouldRiskAmount }" name="shouldRiskAmount" id="shouldRiskAmount" maxlength="13" lay-verify="required|floatAmount" onblur="checkValueNumber(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
							</div>
						</div>
					</div>
				    <div class="layui-form-item">
					    <div class="layui-inline">
							<label class="layui-form-label">已缴风险抵押金金额（元）</label>
							<div class="layui-input-inline">
								<input type="text" value="${effectSure.actRiskAmount }" name="actRiskAmount" id="actRiskAmount" maxlength="13" lay-verify="required|floatAmount" onblur="checkValueNumber(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">已缴纳比例（%）</label>
							<div class="layui-input-inline">
								<input type="text" value="${effectSure.actRiskRate }" id="actRiskRate" name="actRiskRate" style="border: 0px;" readonly="readonly" class="layui-input">
							</div>
						</div>
					</div>
		  		</div>
			</fieldset>
				<fieldset class="layui-elem-field layui-field-title fieldset" id="houseInfo">
			  		<legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">创效明细  ></legend>
				  	<div style="margin-top:20px">
				  	<c:forEach items="${effectSure.effectSureDetails}" var="detail" varStatus="status">
				  		<div class="layui-form-item" id="linkRow${detail.showIdx }">
				  			<div class="layui-inline width98">
						    	<p class="right">创效<label>${detail.showIdx }</label>：</p>
						    	<input type="hidden" name="effectSureDetails[${status.count-1}].showIdx" value="${detail.showIdx }" class="layui-input">
						    </div>
						    <div class="layui-inline">
						    	<label class="layui-form-label width60">创效名称</label>
					      		<div class="layui-input-inline" style="width:150px;">
					      			<input type="text" value="${detail.effectName}" name="effectSureDetails[${status.count-1}].effectName" maxlength="50" lay-verify="required" autocomplete="off" class="layui-input">
					      		</div>
						    </div>
						    <div class="layui-inline">
						      	<label class="layui-form-label width60">创效方式</label>
						      	<div class="layui-input-inline" style="width:110px;">
						      		<select id="selectEffectType" name="effectSureDetails[${status.count-1}].effectType" lay-filter="selectEffectType" lay-verify="required" >
						      			<option value="">请选择</option>
						      			<option value="20" <c:if test="${detail.effectType == '20'}">selected</c:if>>开源创效</option>
								      	<option value="30" <c:if test="${detail.effectType == '30'}">selected</c:if>>节流降本</option>
									</select>
						      		<%-- <infopub:select entireName="-创效方式" value="${detail.effectType }" name="effectSureDetails[0].effectType" layVerify="required" type="dic" groupNo="A00010071" cssClass="layui-input"></infopub:select> --%>
						      	</div>
						    </div>
						    <div class="layui-inline">
						      	<label class="layui-form-label" style="width:120px;">是否计入当期利润</label>
						      	<div class="layui-input-inline" style="width:90px;">
						      		<select id="selectProfitFlag" name="effectSureDetails[${status.count-1}].profitFlag" lay-filter="selectProfitFlag" lay-verify="required" >
						      			<option value="">请选择</option>
						      			<option value="1" <c:if test="${detail.profitFlag == '1'}">selected</c:if>>是</option>
										<option value="0" <c:if test="${detail.profitFlag == '0'}">selected</c:if>>否</option>										
									</select>
						      	</div>
						    </div>
						    <div class="layui-inline">
						      	<label class="layui-form-label" style="width:105px;">创效金额（元）</label>
						      	<div class="layui-input-inline" style="width:120px;">
						      		<input type="text" value="${detail.effectAmount}" name="effectSureDetails[${status.count-1}].effectAmount" maxlength="13" onblur="checkValueNumber(this);arabiaToCN(this,1);" lay-verify="required|floatAmount"  autocomplete="off" class="layui-input">
						      	</div>
						    </div>
						    <div class="layui-inline">
						    	<button type="button" class="layui-btn layui-btn-sm" id="addLinkBtn${status.count }" onclick="addRow(this);"><i class="layui-icon">&#xe654;</i></button>
						    	<button type="button" class="layui-btn layui-btn-sm" <c:if test="${status.count == 1 && fn:length(effectSure.effectSureDetails) == 1}">style="display:none"</c:if> id="delLinkBtn${status.count }" onclick="deleteRow(${status.count })"><i class="layui-icon">&#xe640;</i></button>
						    </div>
					    </div>
					    </c:forEach>
				  	</div>
				</fieldset>
				<fieldset class="layui-elem-field layui-field-title fieldset" >
			  		<legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">附件信息  ></legend>
					  	<div style="margin-top:20px;">
						    <div class="layui-form-item">
							    <label class="layui-form-label" style="width:350px;">支持pdf、excel、word、图片资料，可上传多个</label>
							</div>
						    <div class="layui-form-item">
							    <label class="layui-form-label">附件资料（选填）</label>
							    <div class="layui-input-block">
							    	<div class="layui-upload">
						              	<button type="button" class="layui-btn" id="11-upload-more">上传</button>
				                		<div class="layui-upload-list" id="11-upload-more-list">
				                		<c:forEach items="${effectSure.effectSureAtts }" var="fileAtt">								              			
				              				<div class="layui-upload-img-div" id="upload_img_${fileAtt.id }">
				              					<c:choose>
					              					<c:when test="${fileAtt.fileSuffix == '.jpg' or fileAtt.fileSuffix == '.jpeg' or fileAtt.fileSuffix == '.png'}">
						              					<img src="${fileHttpPre }/${fileAtt.filePath }" title="${fileAtt.fileName}" class="layui-upload-img">
						              				</c:when>
						              				<c:otherwise>
						              					<img src="${ctx}/resources/images/${fn:substring(fileAtt.fileSuffix,1,5)}.jpg" title="${fileAtt.fileName}" class="layui-upload-img">
						              				</c:otherwise>
				              					</c:choose>
				              					<div class="mask">
				              						<a href="javascript:void(0)" onclick="showImg('${fileHttpPre}/${fileAtt.filePath }');">查看</a>
				              						<a href="javascript:void(0)" onclick="del('${fileAtt.id}')">删除</a>
				              						<input type="hidden" value="${fileAtt.fileName}${fileAtt.fileSuffix }|${fileAtt.id}|${fileAtt.filePath }" id="fileAtt_${fileAtt.id}" name="fileAtt" ></input>
				              					</div>
				              					<p>${fileAtt.fileName}</p>
				              				</div>								              			
					              		</c:forEach>
				                		</div>
						            </div>
							    </div>
						  	</div>
					  	</div>
				</fieldset>
				<div class="layui-form-item" style="position: fixed ! important; right: 30px; bottom:45%;z-index:10000;">
					<div class="layui-input-block">
			      		<button class="layui-btn layui-bg-blue layui-btn-normal layui-btn-lg  layui-btn-radius" type="button" lay-submit lay-filter="addInfo_form_submit" id="addInfo_form_submit">
			      		<i class="layui-icon layui-icon-ok layuiadmin-button-btn"></i>
			      		提交
			      		</button>
			      	</div>
			    </div>
			</form>
  		</div>
	</div>
</div>
  <script>
	//静态资源路径前缀
	var staticPath = '${fileHttpPre}';
	var stateJSON = <infopub:dicJson groupNo="A00010028" />;
	
  layui.config({
    base: '${ctx}/resources/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'set', 'upload', 'element', 'laydate'], function(){
    var $ = layui.$
    ,form = layui.form
    ,element = layui.element
    ,laydate = layui.laydate
    ,upload = layui.upload;
    
    laydate.render({
	      elem: '#sent-laydate-year'
	      ,type: 'month'
    	  ,done: function(value, date){
    		  		var proCode = $("input[name=proCode]").val();
    		  		var effectMonth = value;
    		  		if(proCode == ''){
    		  			return;
    		  		}
    		  		getEffectPlan(effectMonth,proCode);
    	  		}
 		});
 	// 正则校验
	form.verify({
		//验证汉字
	    CHS:[
	    	/^[\u0391-\uFFE5]+$/
	    	,'只能输入汉字'
	  	],
	  	//大于0的正整数
	  	intNumber:[
			/^[1-9]\d*$/
			,'请输入正确的数字'
	  	],
	  	//数字只能有两位小数
	  	floatNumber:[
			/^([-]?)([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
			,'请输入正确的数字'
	  	],
	  	//数字大于0，并只能有两位小数
	  	floatAmount:[
			/^([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
			//var pattern=/^((\d+\.\d*[1-9]\d{1})|(\d*[1-9]\d*\.\d{2}))$/; 
			,'请输入正确的数字'
	  	]
	});
	//上传附件
  	upload.render({
	      elem: '#11-upload-more'
	      ,url: basePath + '/effectSure/uploadAtt/'
	      ,data: {
	    	  types:11
	    		}
	      ,multiple: true
	      ,accept: 'file'
	      ,acceptMime: 'application/zip,application/x-rar-compressed,image/jpeg,image/png,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/pdf'
	   	  ,before: function(obj){ //obj参数包含的信息
	   		    layer.load(); //上传loading
	   		  }
	      ,done: function(res){
	    	  //如果上传失败
	          if(res.code > 0){
	        	  layer.closeAll('loading'); //关闭loading
	        	  return layer.msg(res.msg,{icon: 7});
	          }
	          //上传完毕
	   	  	  if(res.entity != null && res.entity.length > 0){
				for(var i in res.entity){
					var effectSureAtt = res.entity[i];
					var arr = effectSureAtt.split("|");
					var imgSrc = "";
					var suffix = arr[0].substring(arr[0].lastIndexOf(".")+1,arr[0].length);
					if(suffix == 'jpg' || suffix == 'png'){
						imgSrc = "${fileHttpPre}/"+arr[2];
					}else{
						imgSrc = "${ctx}/resources/images/"+suffix+".jpg";
					}
	        		$('#11-upload-more-list').append('<div class="layui-upload-img-div" id="upload_img_'+arr[1]+'"><img src="'+imgSrc+'" title="'+ arr[0] +'" class="layui-upload-img"><div class="mask"><a href="javascript:void(0)" onclick="showImg(\''+"${fileHttpPre}"+arr[2] +'\');">查看</a><a href="javascript:void(0)" onclick="del(\''+arr[1]+'\')";>删除</a></div><p>'+arr[0]+'</p><input type="hidden" value="'+effectSureAtt+'" id="fileAtt_'+arr[1]+'" name="fileAtt" ></input></div> ');
				}
		  	  }
	      }
	      ,allDone: function(obj){ //当文件全部被提交后，才触发
	    	  layer.closeAll('loading'); //关闭loading
	      }
	      ,error: function(){
	    	  layer.closeAll('loading'); //关闭loading
	          //上传失败
	          layer.msg("上传失败，请稍后再试~",{icon: 7});
	        }
	    });
	
   	//监听提交
  	form.on('submit(addInfo_form_submit)', function(data){
  		console.log($('#addInfo_form').serialize());
  		$("#addInfo_form_submit").removeAttr("lay-submit").removeClass("layui-bg-blue").addClass("layui-btn-disabled");
  		layer.load();
       	//提交 Ajax 成功后，静态更新表格中的数据
       	$.ajax({
           	type : 'post',
			url : basePath + '/effectSure/save',
           	data: $('#addInfo_form').serialize(),
			success:function(result){
				if(result.success){
					layer.closeAll('loading'); //关闭loading
					layer.msg('提交单据成功~',{icon: 1});
					//两秒后关闭当前页面
					setTimeout(function(){
						/**
						 * 查找父菜单，并刷新
						 */
						var topDoc = $(window.top.document);
						var path = basePath + '/effectSure/list';
						// 获取页面名称
						var name = topDoc.find(".layui-nav-item [lay-href^='" + path + "']").text();
						if(name == '' || name == null){
							name = '创效确认';
						}
						window.parent.layui.index.openTabsPage(path, name);
						var iframe = window.parent.layui.admin.tabsBody(window.parent.layui.admin.tabsPage.index).find(".layadmin-iframe");
						iframe[0].contentWindow.location.reload(true);
						
						/**
						 * 关闭当前页
						 */
						var currPath = basePath + '/effectSure/toCopy';
						var layid = topDoc.find("li[lay-id^='" + currPath + "']").attr('lay-id');
						window.parent.layui.element.tabDelete('layadmin-layout-tabs', layid);//关闭当前页
				        }, 2000);
				}else{
					layer.closeAll('loading'); //关闭loading
  					$("#addInfo_form_submit").removeClass("layui-btn-disabled").addClass("layui-bg-blue").attr("lay-submit","");
					layer.msg(result.msg,{icon: 7});
			  	}
			}
       	});
   	});  
 	// data-type事件
    $('.layui-btn.layuiadmin-btn-admin').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
 	
  	//新增-项目名select监听
    form.on('select(add_select_proId)', function(data){
    	$('#query-input-hrOrgAreId').html('');
    	$('#query-input-hrOrgAreName').html('');
    	$('#query-input-hrOrgProId').html('');
    	$('#query-input-hrOrgProName').html('');
    	$('#query-input-carryOrg').html('');
    	$('#query-input-proLeader').html('');
    	$('#sent-laydate-year').val('');
    	$('#query-input-monthPlanAmount').val('');
    	$('#query-input-yearPlanAmount').val('');
    	$('#query-input-yearDoneAmount').val('');
    	$('#query-input-monthDoneRate').val('');
    	$('#query-input-yearDoneRate').val('');
    	var proId = data.value;
    	if(proId==''||proId==null){
    		layer.msg('请选择项目名称',{icon: 0});
    		return;
    	}else{
    		getProContractById(proId);
    	}		
	});
  	
  });
  
   function getProContractById(id){
	   var $ = layui.$
	  	,form = layui.form
		$.ajax({
			type : "POST", //提交方式  
			url : "${ctx}/effectSure/getProContractById",//路径  
			data : {
				"id" :id
			},//数据，这里使用的是Json格式进行传输  
			success : function(result) {//返回数据根据结果进行相应的处理 
				if(result.flag==true){
					form.val('add_info_from',result.proContractVo); // 填充原值
					//$('#query-input-hrOrgAreId').val(result.proContractVo.hrOrgAreaId);
					$('#query-input-hrOrgAreName').val(result.proContractVo.orgAreName);
					//$('#query-input-hrOrgProId').val(result.proContractVo.hrOrgProId);
					$('#query-input-hrOrgProName').val(result.proContractVo.orgProName);
			    	//$('#query-input-carryOrg').val(result.proContractVo.carryOrg);
			    	//$('#query-input-proLeader').val(result.proContractVo.proLeader);
					form.render();
				}else{
					layer.msg('未查到合同信息~',{icon: 0});
				}
			} 
		});
   }
   
   function getEffectPlan(effectMonth,proCode){
	   var $ = layui.$
	  	,form = layui.form
		$.ajax({
			type : "POST", //提交方式  
			url : "${ctx}/effectSure/getEffectPlanByMonthAndProCode",//路径  
			data : {
				"effectMonth" :effectMonth,
				"proCode" :proCode
			},//数据，这里使用的是Json格式进行传输  
			success : function(result) {//返回数据根据结果进行相应的处理 
				if(result.flag==true){
					var yearPlanAmount = result.yearPlanAmount;
					var monthPlanAmount = result.monthPlanAmount;
					var totalEffectSureAmount = result.totalEffectSureAmount;
					$('#query-input-yearPlanAmount').val(yearPlanAmount);
					$('#query-input-monthPlanAmount').val(monthPlanAmount);
					$('#query-input-yearDoneAmount').val(totalEffectSureAmount);
					//年度累计创效金额
					var totalEffectSureAmount = parseFloat(result.totalEffectSureAmount);
					var monthActAmount = $('#monthActAmount').val();
					if(monthActAmount != ''){
						monthActAmount = parseFloat(monthActAmount);
						if(monthPlanAmount == 0){
							$('#query-input-monthDoneRate').val(0);
						}else{
							var monthDoneRate = (monthActAmount/parseFloat(monthPlanAmount))*100;
							$('#query-input-monthDoneRate').val(monthDoneRate.toFixed(2));
						}
						if(yearPlanAmount == 0){
							$('#query-input-yearDoneRate').val(0);
						}else{
							var yearDoneRate = ((monthActAmount+totalEffectSureAmount)/parseFloat(yearPlanAmount))*100;
							$('#query-input-yearDoneRate').val(yearDoneRate.toFixed(2));
						}
					}
				}else{
					$('#query-input-monthPlanAmount').val('');
			    	$('#query-input-yearPlanAmount').val('');
					$('#query-input-yearDoneAmount').val('');
			    	$('#query-input-monthDoneRate').val('');
			    	$('#query-input-yearDoneRate').val('');
					layer.msg('查询不到对应创效计划数据~',{icon: 0});
				}
			} 
		});
   }

 	//新增一行明细
	function addRow(t){
		var $ = layui.$;
		var delBtnCount = $("button[id^='delLinkBtn']").length;
		if(delBtnCount == 1){
			$("button[id^='delLinkBtn']").each(function(){
				$(this).removeAttr("style");
			});
		}
		var thisid = $(t).attr("id").substring(10);
		thisid = $("div[id=linkRow" + thisid + "]").find("div:first").find("label").html();
		thisid = parseInt(thisid);
		var nextIndex = parseInt(thisid) + 1;
		var maxInd = $("div[id^='linkRow']").length;
		$("div[id^='linkRow']").each(function(){
			$linkRow = $(this);
			var tId = $linkRow.attr("id").substring(7);
			tId = parseInt(tId);
		  	if(tId > maxInd){
		  		maxInd = parseInt(tId);
		  	}
		  	var thisIndex = $linkRow.find("div:first").find("label").html();
		  	thisIndex = parseInt(thisIndex);
		  	var nextId = thisIndex + 1;
		  	if(thisIndex > thisid) {
		  		$("div[id=linkRow" + tId + "]").find("div:first").find("label").html(nextId);
		  		$("div[id=linkRow" + tId + "]").find("div:first").find("input").val(nextId);
		  		$linkRow.find(".layui-input").each(function(){
		  			if($(this).attr("name") != null && $(this).attr("name") != ''){
		  				var inputName = $(this).attr("name").split(".");
		  				var inpName = "effectSureDetails["+thisIndex+"].";
		  				$(this).attr("name",inpName+inputName[1]);
		  			}
		  		});
		  	}
		});
		var ind = maxInd + 1;
		var medalHtml = '';
		medalHtml += '<div class="layui-form-item" id="linkRow'+ind+'">';
		medalHtml += '	<div class="layui-inline width98">';
		medalHtml += '		<p class="right">创效<label>'+nextIndex+'</label>：</p>';
		medalHtml += '		<input type="hidden" name="effectSureDetails['+thisid+'].showIdx" value="'+nextIndex+'" class="layui-input"/>';
		medalHtml += '	</div>';
		medalHtml += '	<div class="layui-inline">';
		medalHtml += '		<label class="layui-form-label width60">创效名称</label>';
		medalHtml += '		<div class="layui-input-inline" style="width:150px;">';
		medalHtml += '			<input type="text" name="effectSureDetails['+thisid+'].effectName" maxlength="50" lay-verify="required" autocomplete="off" class="layui-input">';
		medalHtml += '		</div>';
		medalHtml += '	</div>';
		medalHtml += '	<div class="layui-inline">';
		medalHtml += '		<label class="layui-form-label width60">创效方式</label>';
		medalHtml += '		<div class="layui-input-inline" style="width:110px;">';
		medalHtml += ' 		<select name="effectSureDetails['+thisid+'].effectType" lay-verify="required" class="layui-input">';
		medalHtml += '			<option value="">请选择</option>';
		medalHtml += '			<option value="20">开源创效</option>';
		medalHtml += '			<option value="30">节流降本</option>';
		medalHtml += '		</select>';
  		medalHtml += '		</div>';
  		medalHtml += '	</div>';
  		medalHtml += '	<div class="layui-inline">';
		medalHtml += '		<label class="layui-form-label" style="width:120px;">是否计入当期利润</label>';
		medalHtml += '		<div class="layui-input-inline" style="width:90px;">';
		medalHtml += ' 		<select name="effectSureDetails['+thisid+'].profitFlag" lay-verify="required" class="layui-input">';
		medalHtml += '			<option value="">请选择</option>';
		medalHtml += '			<option value="1">是</option>';
		medalHtml += '			<option value="0">否</option>';
		medalHtml += '		</select>';
  		medalHtml += '		</div>';
  		medalHtml += '	</div>';
  		medalHtml += '	<div class="layui-inline">';
  		medalHtml += '		<label class="layui-form-label" style="width:105px;">创效金额（元）</label>';
  		medalHtml += '		<div class="layui-input-inline" style="width:120px;">';
  		medalHtml += '			<input type="text" name="effectSureDetails['+thisid+'].effectAmount" onblur="checkValueNumber(this);arabiaToCN(this,1);" maxlength="13" lay-verify="required|floatAmount" autocomplete="off" class="layui-input">';
  		medalHtml += '		</div>';
  		medalHtml += '	</div>';
		medalHtml += '	<div class="layui-inline">';
		medalHtml += '		<button type="button" class="layui-btn layui-btn-sm" id="addLinkBtn'+ind+'" onclick="addRow(this);"><i class="layui-icon">&#xe654;</i></button>';
		medalHtml += '		<button type="button" class="layui-btn layui-btn-sm" id="delLinkBtn'+ind+'" onclick="deleteRow('+ind+');"><i class="layui-icon">&#xe640;</i></button>';
		medalHtml += '	</div>';
		medalHtml += '</div>';
		$(t).parent().parent().after(medalHtml);
		layui.form.render();
	}
	
	//删除一行
	function deleteRow(id){
		var $ = layui.$;
		layui.layer.confirm('确定删除？',{icon:3, title :'提示'}, function(index){
		   	var thisid = $("div[id=linkRow" + id + "]").find("div:first").find("label").html();
	    	thisid = parseInt(thisid);
	    	$("div[id^='linkRow']").each(function(){
				var tId = $(this).attr("id").substring(7);
				tId = parseInt(tId);
			  	var thisIndex = $("div[id=linkRow" + tId + "]").find("div:first").find("label").html();
			  	thisIndex = parseInt(thisIndex);
			  	var nextId = thisIndex - 1;
			  	if(thisIndex > thisid) {
			  		$("div[id=linkRow" + tId + "]").find("div:first").find("label").html(nextId);
			  		$("div[id=linkRow" + tId + "]").find("div:first").find("input").val(nextId);
			  		$(this).find(".layui-input").each(function(){
			  			if($(this).attr("name") != null && $(this).attr("name") != ''){
				  			var inputName = $(this).attr("name").split(".");
				  			var inpName = "effectSureDetails["+(nextId-1)+"].";
				  			$(this).attr("name",inpName+inputName[1]);
			  			}
			  		});
			  	}
			});
	    	$("#linkRow"+id).remove();
	    	var delBtnCount = $("button[id^='delLinkBtn']").length;
			if(delBtnCount == 1){
				$("button[id^='delLinkBtn']").each(function(){
					$(this).attr("style","display:none");
				});
			}
			layui.layer.close(index);
			calcSumAmount();
		});
	}
	
	//计算创效金额及相关比例
	function calcSumAmount(){
		var $ = layui.$;
		var rgx = /^([-]?)([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/;
		var name = "effectAmount";
		var totalAmount = 0;
  		$("input[name$=" + name + "]").each(function(){
			var tId = $(this).val();
			var boolrgx = rgx.test(tId);// true
			if(!boolrgx){
				tId=0;
			}else if(parseFloat(tId) > 0){
				totalAmount = totalAmount + parseFloat(tId);
			}
		});
  		$("#monthActAmount").val(totalAmount.toFixed(2));
  		//计算完成比例
  		var yearPlanAmount = $('#query-input-yearPlanAmount').val();
		var monthPlanAmount = $('#query-input-monthPlanAmount').val();
		var yearDoneAmount = $('#query-input-yearDoneAmount').val();
		var monthActAmount = $('#monthActAmount').val();
		if(yearPlanAmount != '' && monthPlanAmount != '' && yearDoneAmount !=''){
			yearDoneAmount = parseFloat(yearDoneAmount);
			if(monthPlanAmount == 0){
				$('#query-input-monthDoneRate').val(0);
			}else{
				var monthDoneRate = (totalAmount/parseFloat(monthPlanAmount))*100;
				$('#query-input-monthDoneRate').val(monthDoneRate.toFixed(2));
			}
			if(yearPlanAmount == 0){
				$('#query-input-yearDoneRate').val(0);
			}else{
				var yearDoneRate = ((totalAmount+yearDoneAmount)/parseFloat(yearPlanAmount))*100;
				$('#query-input-yearDoneRate').val(yearDoneRate.toFixed(2));
			}
		}
	}
	
	//计算已缴纳比例（%）
	function calcRiskRate(){
		var $ = layui.$;
		var shouldRiskAmount = $('#shouldRiskAmount').val();
		var actRiskAmount = $('#actRiskAmount').val();
		var rgx = /^([-]?)([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/;
		if (shouldRiskAmount == '' || shouldRiskAmount == null || !rgx.test(shouldRiskAmount)) {
			return;
		}
		if (actRiskAmount == '' || actRiskAmount == null || !rgx.test(actRiskAmount)) {
			return;
		}
		
		//计算完成比例
		if(shouldRiskAmount !=0 && actRiskAmount !=0){
			shouldRiskAmount = parseFloat(shouldRiskAmount);
			actRiskAmount = parseFloat(actRiskAmount);
			var actRiskRate = (actRiskAmount/shouldRiskAmount)*100;
  			$("#actRiskRate").val(actRiskRate.toFixed(2));
		}else{
			var actRiskRate = 0;
			$("#actRiskRate").val(actRiskRate.toFixed(2));
		}
	}
	
	//删除文件
	function del(index){
		layui.$("#fileAtt_"+index).remove();
		layui.$("#upload_img_"+index).remove();
	}
  
	//根据url查看文件
	function showImg(url){
		var openWin = window.open(url,'','left=410,height=768, width=1024, top=200,  toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
	}
	// 请输入正确数字，且保留两位小数！
	function checkValueNumber(obj) {
		var $ = layui.$;
		if (obj.value == '' || obj.value == null) {
			return;
		}
		var rgx = /^([-]?)([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/;
		var boolrgx = rgx.test(obj.value);// true 
		if (!boolrgx){
			obj.value=0;
			layer.msg('请输入正确数字，且保留两位小数！');
		}
		if(obj.name.indexOf('effectAmount') != -1){
			calcSumAmount();
		}else if(obj.name.indexOf('RiskAmount') != -1){
			calcRiskRate();
		}
	}
  </script>
</body>
</html>

